﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using Fluent;
using PefStudio.Base;

namespace PefStudio.Windows
{
    class CreateService
    {
        //internal static void CreateRibbonTabItems(ObservableCollection<RibbonTabItem> tabItems, IEnumerable<IRibbonTabItem> items)
        //{
        //    var sortedExtensionItems = ExtensionsService.Sort(items);
        //    foreach (var extensionItem in sortedExtensionItems)
        //    {
        //        var tab = extensionItem as RibbonTabItem;
        //        if (tab != null) tabItems.Add(tab);
        //    }
        //}

        //internal static void CreateRibbonContextualTabGroups(ObservableCollection<RibbonContextualTabGroup> tabGroups, IEnumerable<IRibbonContextualTabGroup> items)
        //{
        //    var sortedExtensionItems = ExtensionsService.Sort(items);
        //    foreach (var extensionItem in sortedExtensionItems)
        //    {
        //        var tab = extensionItem as RibbonContextualTabGroup;
        //        if (tab != null) tabGroups.Add(tab);
        //    }
        //}

        //internal static void CreateRibbonGroupBoxs(ObservableCollection<RibbonGroupBox> groupBoxs, IEnumerable<IRibbonGroupBox> items)
        //{
        //    var sortedExtensionItems = ExtensionsService.Sort(items);
        //    foreach (var extensionItem in sortedExtensionItems)
        //    {
        //        var groupBox = extensionItem as RibbonGroupBox;
        //        if (groupBox != null) groupBoxs.Add(groupBox);
        //    }
        //}

        //internal static void CreateRibbonToolBarLayoutDefinitions(ObservableCollection<RibbonToolBarLayoutDefinition> itemCollection, IEnumerable<IRibbonToolBarLayoutDefinition> items)
        //{
        //    var sortedExtensionItems = ExtensionsService.Sort(items);
        //    foreach (var extensionItem in sortedExtensionItems)
        //    {
        //        var newItem = extensionItem as RibbonToolBarLayoutDefinition;
        //        if (newItem != null) itemCollection.Add(newItem);
        //    }
        //}

        internal static void CreateCollection<T1, T2>(ObservableCollection<T1> itemCollection, IEnumerable<T2> items)
            where T2 : IExtension
            where T1 : class
        {
            var sortedExtensionItems = ExtensionsService.Sort(items).Cast<T1>();
            foreach (var extensionItem in sortedExtensionItems)
            {
                var newItem = extensionItem;
                if (newItem != null) itemCollection.Add(newItem);
            }
        }

        internal static void CreateCollection<T>(ItemCollection itemCollection, IEnumerable<T> items) where T : IExtension
        {
            var sortedExtensionItems = ExtensionsService.Sort(items);
            foreach (var extensionItem in sortedExtensionItems)
            {
                itemCollection.Add(extensionItem);
            }
        }
    }
}
